from nicegui import ui, app
from orm import manager

class personalInspection():
    def __init__(self, username="none"):
        if(username=="none"):
            self.user = manager.get_user(app.storage.user["username"])
        else:
            self.user = manager.get_user(username)
        self.alluser = list(manager.select_all_user())
        userdata = []
        for user in self.alluser:
            historys = manager.get_histroy(user.id)
            tmp = []
            cor = 0
            for solu in historys:
                if solu.score == 100:
                    cor+=1
            tmp.append(len(historys))
            tmp.append((cor+0.0001)/(len(historys)+0.1))
            tmp.append(5)
            userdata.append(tmp)
        self.history = manager.get_histroy(self.user.id)
        self.correct = 0
        for solu in self.history:
            if solu.score == 100:
                self.correct += 1
        chart = ui.chart({
            'title': {"text": "个人能力图"},
            "chart": {
                "type": 'bubble',
                "plotBorderWidth": 1,
                "zoomType": 'xy'
            },
            "xAxis": {
                "gridLineWidth": 1,
                "title": {
                    "text": '做题数量'
                },
            },
            "yAxis": {
                "startOnTick": False,
                "endOnTick": False,
                "title": {
                    "text": '正确率'
                },
            },

            "series": [{
                "data": userdata,
                "sizeBy": 'area',
                "name": '所有用户'
            }, {
                "data": [
                    [len(self.history), (self.correct+0.0001)/(len(self.history)+0.1), 30]
                ],
                "sizeBy": 'area',
                "name": '你的个人能力位置'
            }]
        }).classes('w-full h-fit')